/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.qudex.qudexservlet.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.igfay.jfig.JFig;
import org.igfay.jfig.JFigException;

public class TemplateServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2702294768966647086L;
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		// Get the collection ID
		String collectionId = req.getParameter("collection");
		// Construct URLs
		String urlCollections = "qudexsparql?collection=" + collectionId + "&operation=1";
		String urlFiles = "qudexsparql?collection=" + collectionId + "&operation=2";
		String urlCategories = "qudexsparql?collection=" + collectionId + "&operation=3";
		// set values
		req.setAttribute("urlCollections", urlCollections);
		req.setAttribute("urlFiles", urlFiles);
		req.setAttribute("urlCategories", urlCategories);
		req.setAttribute("colId", collectionId);
		try {
			req.setAttribute("server", JFig.getInstance().getValue("mulgaraServer", "server"));
			req.setAttribute("serverScript", JFig.getInstance().getValue("mulgaraServer", "serverScript"));
		} catch (JFigException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		RequestDispatcher requestDispatcher =  req.getRequestDispatcher("qudex-visualiser-template.vm");
		requestDispatcher.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
